package BookSystem.operation;

import BookSystem.book.Book;
import BookSystem.book.BookList;

import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 */
public class AddOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书信息: ");
        Scanner in = new Scanner(System.in);
        System.out.print("输入书名: ");
        String name = in.nextLine();
        System.out.print("输入作者: ");
        String author = in.nextLine();
        System.out.print("输入类别: ");
        String type = in.nextLine();
        System.out.print("输入价格: ");
        int price = in.nextInt();

        Book book = new Book(name, author, price, type);

        int currentSize = bookList.getUseSize();
        for (int i = 0; i < currentSize; i++) {
            Book temp = bookList.getBook(i);
            if (temp.getName().equals(name)){
                System.out.println("该书已存在！！！");
                return;
            }
        }

        bookList.setBook(book);
        bookList.setUseSize(currentSize + 1);


    }
}
